home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / TUT1-9.ZIP / COPPERS.PAS < prev    next >
Pascal/Delphi Source File  |  1994-01-14  |  6KB  |  172 lines

  1. Program Copper;
  2.  
  3. Uses Crt;
  4.  
  5. Const MaxRasters = 895;   {  (64+64) * 7 = 896   }
  6.       WaitHoriz = FALSE;      { Wait for horizontal retace? }
  7.       DisableInterrupts = TRUE;  { Disable interupts ? }
  8.  
  9. Var Rastercolors : Array[0..MaxRasters,1..3] Of Byte;
  10.     Position,temp,deg: Integer;   { Position = What is the first color? }
  11.                                   { Temp = What color for indiv. lines }
  12.                                   { Deg = degree for movement }
  13.     ret,r,g,b:byte;               { Ret = verticle retrace??? }
  14.  
  15.  
  16. {──────────────────────────────────────────────────────────────────────────}
  17. Procedure RampColors (r,g,b:boolean);
  18.   { Create a ramp of colors in the RasterColors array, from black to bright
  19.     to black again. The R,G,B variables are booleans that determine what mix
  20.     of colors make up the ramp. }
  21. VAR Loop1:Integer;
  22. BEGIN
  23.   For loop1:=0 To 63 Do Begin
  24.     if r then RasterColors[Temp,1]:=loop1 else RasterColors[Temp,1]:=0;
  25.     if g then RasterColors[Temp,2]:=loop1 else RasterColors[Temp,2]:=0;
  26.     if b then RasterColors[Temp,3]:=loop1 else RasterColors[Temp,3]:=0;
  27.     Temp:=Temp+1;
  28.   End;
  29.   For loop1:=63 DownTo 0 Do Begin
  30.     if r then RasterColors[Temp,1]:=loop1 else RasterColors[Temp,1]:=0;
  31.     if g then RasterColors[Temp,2]:=loop1 else RasterColors[Temp,2]:=0;
  32.     if b then RasterColors[Temp,3]:=loop1 else RasterColors[Temp,3]:=0;
  33.     Temp:=Temp+1;
  34.   End;
  35. END;
  36.  
  37.  
  38. {──────────────────────────────────────────────────────────────────────────}
  39. Function rad (theta : real) : real;
  40.   {  This calculates the degrees of an angle }
  41. BEGIN
  42.   rad := theta * pi / 180
  43. END;
  44.  
  45.  
  46. {──────────────────────────────────────────────────────────────────────────}
  47. Procedure Init;
  48.   { Initialise all variables }
  49. BEGIN
  50.   Temp :=0;
  51.   Deg  :=0;
  52.   Position:=0;
  53.  
  54.   RampColors (TRUE,FALSE,FALSE);    { Red Ramp }
  55.   RampColors (FALSE,TRUE,FALSE);    { Green Ramp }
  56.   RampColors (FALSE,FALSE,TRUE);    { Blue Ramp }
  57.   RampColors (TRUE,TRUE,FALSE);     { Yellow Ramp }
  58.   RampColors (TRUE,FALSE,TRUE);     { Purple Ramp }
  59.   RampColors (FALSE,TRUE,TRUE);     { Light Blue Ramp }
  60.   RampColors (TRUE,TRUE,TRUE);      { White Ramp }
  61.  
  62.   if DisableInterrupts then
  63.     Port[$21]:=1;                   { Disable interupts. Makes scrolling
  64.                                       much smoother, but MUST BE RESTORED
  65.                                       AT PROGRAM END! }
  66. END;
  67.  
  68.  
  69. {──────────────────────────────────────────────────────────────────────────}
  70. PROCEDURE Play;
  71.   { Make the copper bars }
  72. BEGIN
  73.   Repeat
  74.     Temp:=Position;
  75.  
  76.     Repeat
  77.       r:=RasterColors[Temp,1];
  78.       g:=RasterColors[Temp,2];
  79.       b:=RasterColors[Temp,3];
  80.  
  81.       asm
  82.         mov     dx,3c8h
  83.         mov     al,0
  84.         out     dx,al
  85.         inc     dx
  86.         mov     al,[r]
  87.         out     dx,al
  88.         mov     al,[g]
  89.         out     dx,al
  90.         mov     al,[b]
  91.         out     dx,al    { Change color 0's pallette }
  92.       end;    { Calling a separate pal procedure is too slow ... }
  93.  
  94.       if waithoriz then
  95.         asm
  96.           mov     dx,03dah
  97. @WaitHRTEnd:
  98.           in      al,dx
  99.           test    al,01h
  100.           jz      @WaitHRTEnd            { Wait until horiz. retrace finished }
  101.       end;
  102.  
  103.       Inc(temp);                          { Increase colorcount }
  104.       If temp>MaxRasters Then temp:=0;           { Limit }
  105.  
  106.       asm
  107.         mov     dx,03dah
  108.         in      al,dx
  109.         test    al,8
  110.         jz      @Zero      { If not in Vert. Retrace, change color }
  111.         mov     ret,1
  112.         jmp     @Fin
  113. @Zero :
  114.         mov     ret,0
  115. @Fin :
  116.       end;
  117.     Until ret=1;
  118.     { During vert. retrace ... }
  119.  
  120.     deg:=deg+1;
  121.     position:=position+round (sin (rad (deg))*15);    { For scrolling }
  122.     If position>MaxRasters Then position:=0;            { Limits }
  123.     If position<0 Then position:=MaxRasters;
  124.  
  125.   Until Port[$60]<$80;   { has a key been pressed? }
  126.                          { Until keypressed takes too long ... }
  127.  
  128.   asm
  129.     mov    dx,3c8h
  130.     mov    al,0
  131.     out    dx,al
  132.     inc    dx
  133.     mov    al,0
  134.     out    dx,al
  135.     mov    al,0
  136.     out    dx,al
  137.     mov    al,0
  138.     out    dx,al
  139.   end;   { Restore pallette zero to black }
  140.   if DisableInterrupts then
  141.     Port[$21]:=0;                                { Enable interrupts }
  142. END;
  143.  
  144. BEGIN
  145.   ClrScr;
  146.   Writeln ('Hi there!  This is a small litttle program to demonstrate how to do');
  147.   Writeln ('copper bars in textmode through SIMPLE pallette manipulation. It was');
  148.   Writeln ('mainly coded in order to display how to check for horizontal retrace.');
  149.   Writeln;
  150.   Writeln ('To achive this effect, we continally alter the pallette of color 0,');
  151.   Writeln ('according to a color gradient we have precalculated. If we alter this');
  152.   Writeln ('color once every horizontal retrace, we get a cool spectrum, which you');
  153.   Writeln ('can see behind this text. To obtain movement, we change wich color to');
  154.   Writeln ('start with every verticle retrace. The code is easy do understand and');
  155.   Writeln ('well documented, so you shouldn''t have any problems.');
  156.   Writeln;
  157.   Writeln ('The verticle retrace and many other things are discussed in the ASPHYXIA');
  158.   Writeln ('VGA Trainer Series, available on ASPHYXIA BBS (031) 765 5312');
  159.   Writeln;
  160.   Writeln ('Do you like it?  If you want to get in contact with me (Denthor) or');
  161.   Writeln ('any of the other ASPHYXIA members (Goth, EzE, Fubar, Nobody), leave');
  162.   Writeln ('mail to those names on Connectix BBS (031) 2669992, or write to');
  163.   Writeln ('me (Grant Smith/DENTHOR) on the ASPHYXIA BBS or the For Your Eyes');
  164.   Writeln ('Only BBS.');
  165.   Writeln;
  166.   Writeln ('You may also get me on (031) 732129, or write to P.O.Box 270 Kloof 3640');
  167.   Writeln;
  168.   Writeln ('Bye,');
  169.   Writeln (' - Denthor');
  170.   Init;
  171.   Play;
  172. END.